package com.tzkyzj.tiremanager.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonManagedReference;

import javax.persistence.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Entity
@Table(name = "settlement_records")
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class SettlementRecord {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(nullable = false)
    private String plateNumber;

    private String transportCompany;

    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDate settlementDate;

    @Column(nullable = false)
    private Double totalCost;

    private String remarks;

    @Column(nullable = false)
    private LocalDateTime createTime;

    private String invoiceNumber;

    // 新增 userId 字段
    @Column(name = "user_id")
    private Long userId;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "settlementRecord", fetch = FetchType.LAZY)
    @JsonManagedReference
    private List<SettlementItem> items;

    // 构造函数
    public SettlementRecord() {
        this.createTime = LocalDateTime.now();
        this.invoiceNumber = "INV" + System.currentTimeMillis();
    }

    // getters and setters
    public Long getId() { return id; }
    public void setId(Long id) { this.id = id; }

    public String getPlateNumber() { return plateNumber; }
    public void setPlateNumber(String plateNumber) { this.plateNumber = plateNumber; }

    public String getTransportCompany() { return transportCompany; }
    public void setTransportCompany(String transportCompany) { this.transportCompany = transportCompany; }

    public LocalDate getSettlementDate() { return settlementDate; }
    public void setSettlementDate(LocalDate settlementDate) { this.settlementDate = settlementDate; }

    public Double getTotalCost() { return totalCost; }
    public void setTotalCost(Double totalCost) { this.totalCost = totalCost; }

    public String getRemarks() { return remarks; }
    public void setRemarks(String remarks) { this.remarks = remarks; }

    public LocalDateTime getCreateTime() { return createTime; }
    public void setCreateTime(LocalDateTime createTime) { this.createTime = createTime; }

    public String getInvoiceNumber() { return invoiceNumber; }
    public void setInvoiceNumber(String invoiceNumber) { this.invoiceNumber = invoiceNumber; }

    // 新增 userId 的 getter 和 setter
    public Long getUserId() { return userId; }
    public void setUserId(Long userId) { this.userId = userId; }

    public List<SettlementItem> getItems() { return items; }
    public void setItems(List<SettlementItem> items) { this.items = items; }
}